home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1994 March / Internet Info CD-ROM (Walnut Creek) (March 1994).iso / networking / osi / isode / dosisode / DOSISODE80.ZIP / ISODE8.WRK / UNIX / LIB / GET.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-08  |  3.3 KB  |  240 lines

  1. #include <stdio.h>
  2. #include <strings.h>
  3. #include <pwd.h>
  4. #include <sys/types.h>
  5. #include <sys/time.h>
  6. #include <fiddle.h>
  7.  
  8. char *malloc(), *unix2dos();
  9. static int debug = 0;
  10. static char PWDB[] = "/etc/passwd";
  11.  
  12. static FILE *pwf = NULL;
  13. static char line[129];
  14. static struct passwd pw;
  15. static char *any();
  16. int _pw_stayopen;
  17. FILE *fopen();
  18. char *fgets();
  19.  
  20. #undef time
  21.  
  22. char **environ;
  23.  
  24. static char encrypted_passwd[128];
  25. char *crypt(key,salt)
  26. const char *key, *salt;
  27. {
  28.     strcpy(encrypted_passwd,key);
  29.     return(encrypted_passwd);
  30. }
  31.  
  32. struct passwd *getpwnam(name)
  33. char *name;
  34. {
  35.     register struct passwd *p;
  36.     register char **cp;
  37.  
  38.     setpwent();
  39.     while (p = getpwent()) {
  40.         if (strcmp(name, p->pw_name) == 0) break;
  41.     }
  42.     if (!_pw_stayopen) endpwent();
  43.     return (p);
  44. }
  45.  
  46. struct passwd *getpwuid(uid)
  47. int uid;
  48. {
  49.     register struct passwd *p;
  50.     register char **cp;
  51.  
  52.     setpwent();
  53.     while (p = getpwent()) {
  54.         if (p->pw_uid == uid) break;
  55.     }
  56.     if (!_pw_stayopen) endpwent();
  57.     return (p);
  58. }
  59.  
  60. struct passwd *getpwent()
  61. {
  62.     char *p;
  63.     register char *cp, **q;
  64.  
  65.     if (pwf == NULL && (pwf = fopen(PWDB, "r" )) == NULL)
  66.         return (NULL);
  67. again:
  68.     if ((p = fgets(line, BUFSIZ, pwf)) == NULL)
  69.         return (NULL);
  70.     if (*p == '#') goto again;
  71.     cp = strchr(p, ':');
  72.     if (cp == NULL) goto wrong;
  73.     *cp++ = '\0';
  74.     pw.pw_name = p;
  75.     p = strchr(cp, ':');
  76.     if (p == NULL) goto wrong;
  77.     *p++ = '\0';
  78.     pw.pw_passwd = cp;
  79.     cp = strchr(p, ':');
  80.     if (cp == NULL) goto wrong;
  81.     *cp++ = '\0';
  82.     pw.pw_uid = atoi(p);
  83.     p = strchr(cp, ':');
  84.     if (p == NULL) goto wrong;
  85.     *p++ = '\0';
  86.     pw.pw_gid = atoi(cp);
  87.     cp = strchr(p, ':');
  88.     if (cp == NULL) goto wrong;
  89.     *cp++ = '\0';
  90.     pw.pw_gecos = p;
  91.     p = strchr(cp, ':');
  92.     if (p == NULL) goto wrong;
  93.     *p++ = '\0';
  94.     pw.pw_dir = cp;
  95.     return (&pw);
  96. wrong:
  97.     fprintf(stderr,"Error in format of /etc/passwd file\n - %s -\n",line);
  98.     return(NULL);
  99. }
  100.  
  101. setpwent()
  102. {
  103.     if (pwf == NULL)
  104.         pwf = fopen(PWDB, "r" );
  105.     else
  106.         rewind(pwf);
  107.     _pw_stayopen = 1;
  108. }
  109.  
  110. endpwent()
  111. {
  112.     if (pwf) {
  113.         fclose(pwf);
  114.         pwf = NULL;
  115.     }
  116.     _pw_stayopen = 0;
  117. }
  118.  
  119. unsigned si_getuid()
  120. {
  121.     return(0);
  122. }
  123.  
  124. int si_geteuid()
  125. {
  126.     return(0);
  127. }
  128.  
  129. int getppid()
  130. {
  131.     return(0);
  132. }
  133. seteuid(euid)
  134. int euid;
  135. {
  136.   return(0);
  137. }
  138.  
  139. setruid(ruid)
  140. int ruid;
  141. {
  142.   return(0);
  143. }
  144.  
  145. getitimer(which, value)
  146. int which;
  147. struct itimerval *value;
  148. {
  149. if (debug) fprintf(stderr,"getitimer called\n");
  150.    return(-1);
  151. }
  152.  
  153. setitimer(which, value, ovalue)
  154. int which;
  155. struct itimerval *value, *ovalue;
  156. {
  157. if (debug) fprintf(stderr,"setitimer called\n");
  158.    return(-1);
  159. }
  160.  
  161. getusertty(name, tty)
  162. char *name, *tty;
  163. {
  164. if (debug) fprintf(stderr,"getusertty called\n");
  165. }
  166.  
  167. getdtablesize()
  168. {
  169.    return(16);
  170. }
  171.  
  172. getpagesize()
  173. {
  174.    return(BUFSIZ);
  175. }
  176.  
  177. struct group *getgrent()
  178. {
  179.    return(NULL);
  180. }
  181.  
  182. struct group *getgrgid(gid)
  183. int gid;
  184. {
  185.    return(NULL);
  186. }
  187.  
  188. struct group *getgrnam(name)
  189. char *name;
  190. {
  191.    return(NULL);
  192. }
  193.  
  194. setgrent()
  195. {
  196. }
  197.  
  198. endgrent()
  199. {
  200. }
  201.  
  202. initgroups(name,basegid)
  203. char *name;
  204. int basegid;
  205. {
  206. }
  207.  
  208. int fork()
  209. {
  210. }
  211.  
  212. int vfork()
  213. {
  214. }
  215.  
  216. int pipe(p)
  217. int *p;
  218. {
  219. }
  220.  
  221. int wait(status)
  222. int *status;
  223. {
  224. }
  225.  
  226. int wait3(status, options, rusage)
  227. union wait *status;
  228. int options;
  229. struct rusage *rusage;
  230. {
  231. }
  232.  
  233. int chroot(dirname)
  234. char *dirname;
  235. {
  236.     return(0);
  237. }
  238.  
  239.  
  240.